<?php

	/**
	 * @package Yomm
	 * @author bsuter
	 *
	 */
	Class Yomm_Library_Export
	{
		private $header_row = array();
		
		private $content_rows = array();
		
		/**
		 * import CSV Object for example the ydsql select statement result
		 */
		public function importObject($object)
		{ $i = 0;
			foreach($object as $values)
			{
				foreach($values as $head => $content)
				{
					if($i == 0)
					{
						$this->header_row[] = $head;
					}
					$this->content_rows[$i][] = strip_tags(str_replace(array('\n','\r'), '', $content));
				} $i++;
			}
		}
		
		public function importArray($array)
		{
			// TODO: code it
		}
		
		public function exportCSV()
		{
			$csv = '"' . implode('";"', $this->header_row) . '";' . "\r\n";
			
			foreach($this->content_rows as $value)
			{
				$csv .= '"' . $this->clearBreaks(implode('";"', $value)) . '";' . "\r\n";
			}
			
			return $csv;
		}
		
		public function exportXML()
		{
			// TODO: code it
		}
		
		public function exportEXCEL()
		{
			// TODO: code it
		}
		
		private function clearBreaks($text)
		{
			return str_replace(array("\n", "\r"), "", $text);
		}
	}